package cn.xdwanj.config

import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.baomidou.mybatisplus.generator.FastAutoGenerator
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine
import java.util.*

fun main(args: Array<String>) {
  val properties = Properties().apply { load(ClassLoader.getSystemClassLoader().getResourceAsStream("db.properties")) }
  val (driver, url, username, password) = properties.run {
    listOf(
      getProperty("driver"),
      getProperty("url"),
      getProperty("user"),
      getProperty("password"),
    ).map {
      it.also { println("it = $it") }
    }
  }


  FastAutoGenerator.create(
    """jdbc:sqlite:D:\Project\Kotlin\EnglishReview\src\main\resources\EnglishRootWords.db""",
    "",
    ""
  )
    .globalConfig { builder ->
      builder
        .author("XDwanj")
        .outputDir("D:\\")
        .enableKotlin()
        .fileOverride()
    }
    .packageConfig { builder ->
      builder
        .parent("cn.xdwanj")
    }
    .strategyConfig { builder ->
      builder
        .mapperBuilder()
        .formatMapperFileName("%sMapper")
        .enableMapperAnnotation()
        .superClass(BaseMapper::class.java)

        .serviceBuilder()
        .formatServiceFileName("%sService")
        .formatServiceImplFileName("%sServiceImp")

        .entityBuilder()
        .disableSerialVersionUID()
        .naming(NamingStrategy.underline_to_camel)
        .columnNaming(NamingStrategy.underline_to_camel)
        .enableTableFieldAnnotation()

        .controllerBuilder()
        .formatFileName("%sController")
        .enableRestStyle()
    }
    .templateEngine(
      VelocityTemplateEngine()
    )
    .execute()


}
